package com.awesome.livedatademo.livedataviewmodel

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.awesome.livedatademo.R

/**
 * LiveData + ViewModel
 */
class ViewModelActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_model)
        val viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        val observer = Observer<String> {
            findViewById<TextView>(R.id.textview).text = it
        }
        viewModel.userLiveData.observe(this, observer)
        viewModel.loadUser()
    }
}